package cn.edu.zafu.bigdata.x.zhouyuyan.work8;

import java.io.*;

public class RhymingWords {
    public static Reader reverse(Reader source) throws IOException {
        BufferedReader in = new BufferedReader(source);
        PipedWriter pipedOut = new PipedWriter();
        PipedReader pipedIn = new PipedReader(pipedOut);
        PrintWriter out = new PrintWriter(pipedOut);
        new ReverseThread(out, in).start();
        return pipedIn;
    }
    public static Reader sort(Reader source) throws IOException {
        BufferedReader in = new BufferedReader(source);
        PipedWriter pipedOut = new PipedWriter();
        PipedReader pipedIn = new PipedReader(pipedOut);
        PrintWriter out = new PrintWriter(pipedOut);
        new SortThread(out, in).start();
        return pipedIn;
    }

    public static void main(String[] args) throws IOException {
        FileReader words = new FileReader("src/main/java/cn/edu/zafu/bigdata/x/zhouyuyan/work8/file/word.txt");
        Reader rhymedWords = reverse(sort(words));
        BufferedReader in = new BufferedReader(rhymedWords);
        String word;
        while ((word = in.readLine()) != null) {
            System.out.println(word);
        }
        words.close();
        rhymedWords.close();
    }
}
